/*
 *  $Id: Names.cs 1172 2010-11-06 12:04:25Z thenn.erannor $
 *	This file is a part of Ragima CCG.
 *	(C) 2008-2010 Ragima development group.
 *
 *	Licensed under the terms of the GNU GPL License version 2.
 *
 */

using Nereal.Serialization;

using Ragima.Languages;

namespace Ragima.Serialization {
    [TypeInfo(typeof(Names))]
    public class NamesTypeInfo : TypeInfo<Names> {
        private MemberWrapper _itemMember;

        public NamesTypeInfo() {
            _itemMember = MemberWrapper.CreateItem<LocalizedName>("name");
        }

        public override bool IsUpdateable {
            get { return true; }
        }

        public override bool IsElement(MemberWrapper member) {
            return true;
        }

        /// <summary>
        /// Невозможно клонирование экземпляра.
        /// </summary>
        public override Names Clone(Names value) {
            throw new System.NotImplementedException();
        }

        public override bool IsNull(Names value) {
            return value == null;
        }

        public override bool Equals(Names a, Names b) {
            return a == b;
        }

        /// <summary>
        /// Невозможна десериализация нового экземпляра, только обновление старого.
        /// </summary>
        public override Names Deserialize(MemberWrapper member, DeserializationContext context) {
            throw new System.NotImplementedException();
        }

        public override void Deserialize(MemberWrapper member, DeserializationContext context, Names value) {
            value.ClearResources();
            foreach (var resource in context.ReadElements<LocalizedName>(_itemMember))
                value.AddResource(resource);
        }

        public override void Serialize(MemberWrapper member, SerializationContext context, Names value) {
            context.WriteElements(_itemMember, value.GetResources());
        }
    }
}
